package com.espirit.common;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import com.espirit.eap.RevisionHistoryAware;
import com.espirit.eap.annotation.DomainModel;
import com.espirit.eap.manager.RevisionHistory;
import com.espirit.eap.relationship.Party;
import com.espirit.eap.sa.User;


@Entity
@DomainModel
public class SysLog implements Serializable ,RevisionHistoryAware{

	private static final long serialVersionUID = -4856342299834425084L;
	
	private Integer id;
	private Party party;
	private RevisionHistory revisionHistory;
	private String content;
	private Boolean system;
	private User owner;
	private String operator;
	
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@ManyToOne(targetEntity=Party.class,fetch=FetchType.EAGER)
	public Party getParty() {
		return party;
	}
	public void setParty(Party party) {
		this.party = party;
	}
	
	@Embedded 
	public RevisionHistory getRevisionHistory() {
		return revisionHistory;
	}
	public void setRevisionHistory(RevisionHistory revisionHistory) {
		this.revisionHistory = revisionHistory;
	}
	
	@Column(length=500)
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	
	public Boolean getSystem() {
		return system;
	}
	public void setSystem(Boolean system) {
		this.system = system;
	}

	private String richContent;

	public void setRichContent(String richContent) {
		this.richContent = richContent;
	}
	
	@Transient
	public String getRichContent() {
		return richContent;
	}
	@Override
	public RevisionHistory safeRevisionHistory() {
		if (revisionHistory == null) {
			revisionHistory = new RevisionHistory();
		}
		return revisionHistory;
	}
	
	@ManyToOne(targetEntity = User.class,fetch=FetchType.LAZY)
	public User getOwner() {
		return owner;
	}
	
	public void setOwner(User owner) {
		this.owner = owner;
	}
	

	public String getOperator() {
		return operator;
	}
	public void setOperator(String operator) {
		this.operator = operator;
	}

	
}
